package com.xinzhiduming.listviewadapter;

import java.util.ArrayList;

import com.xinzhiduming.listviewadapter.SelectCityListViewAdapter.ViewHoler;
import com.xinzhiduming.weatherinfo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class WeatherDetailAdapter extends BaseAdapter{
	LayoutInflater mLayoutInflater = null;
	Context mContext = null;
	ArrayList<String> mTemperatureList = new ArrayList<String>();
	ArrayList<String> mWeatherList = new ArrayList<String>();
	ArrayList<String> mWindList = new ArrayList<String>();
	ArrayList<String> mDateList = new ArrayList<String>();
	ArrayList<String> mWeekList = new ArrayList<String>();
	
	public WeatherDetailAdapter(Context context, ArrayList<String> temperatureList, ArrayList<String> weatherList, ArrayList<String> windList, ArrayList<String> dateList, ArrayList<String> weekList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mTemperatureList = temperatureList;
		mWeatherList = weatherList;
		mWindList = windList;
		mDateList = dateList;
		mWeekList = weekList;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mTemperatureList.size();
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return mTemperatureList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHoler viewHoler;
		if (convertView == null) {
			viewHoler = new ViewHoler();
			convertView = mLayoutInflater.inflate(R.layout.weather_list_view_deatil, null);
			viewHoler.temperatureTV = (TextView) convertView.findViewById(R.id.temperature_tv);
			viewHoler.weatherTV = (TextView) convertView.findViewById(R.id.weather_tv);
			viewHoler.windTV = (TextView) convertView.findViewById(R.id.wind_tv);
			viewHoler.dateTV = (TextView) convertView.findViewById(R.id.date_tv);
			viewHoler.weekTV = (TextView) convertView.findViewById(R.id.week_tv);
			convertView.setTag(viewHoler);
		}else {
			viewHoler = (ViewHoler) convertView.getTag();
		}
		if (mTemperatureList.size() > 1) {
			viewHoler.temperatureTV.setText(mTemperatureList.get(position));
			viewHoler.weatherTV.setText(mWeatherList.get(position));
			viewHoler.windTV.setText(mWindList.get(position));
			viewHoler.dateTV.setText(mDateList.get(position));
			viewHoler.weekTV.setText(mWeekList.get(position));
		}

		if (position %2 == 0) {
			viewHoler.temperatureTV.setTextColor(android.graphics.Color.MAGENTA);
			viewHoler.weatherTV.setTextColor(android.graphics.Color.MAGENTA);
			viewHoler.windTV.setTextColor(android.graphics.Color.MAGENTA);
			viewHoler.dateTV.setTextColor(android.graphics.Color.MAGENTA);
			viewHoler.weekTV.setTextColor(android.graphics.Color.MAGENTA);
		} else {
			viewHoler.temperatureTV.setTextColor(android.graphics.Color.CYAN);
			viewHoler.weatherTV.setTextColor(android.graphics.Color.CYAN);
			viewHoler.windTV.setTextColor(android.graphics.Color.CYAN);
			viewHoler.dateTV.setTextColor(android.graphics.Color.CYAN);
			viewHoler.weekTV.setTextColor(android.graphics.Color.CYAN);
		}
		return convertView;
	}

	static class ViewHoler {
		public TextView temperatureTV;
		public TextView weatherTV;
		public TextView windTV;
		public TextView dateTV;
		public TextView weekTV;
	}
}
